<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('租户管理列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
<!--                        <li>-->
<!--                            <label>项目名称：</label>-->
<!--                            <select name="projectId" id="projectId" class="form-control m-b"  >-->
<!--                                <option value="" >所有</option>-->
<!--                                <option th:each="a:${sysProjects}" th:text="${a.projectName}" th:value="${a.projectId}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <label>租户名称：</label>
                            <select name="tenantName" class="form-control" id="tenantName" required>
                                <option value="">请选择</option>
                                <option th:each="tenantInfo:${tenantInfos}" th:text="${tenantInfo.tenantName}" th:value="${tenantInfo.tenantName}"></option>
                            </select>
                        </li>
                        <li>
                            <label>租户楼层：</label>
                            <select name="tenantFloor" class="form-control" id="tenantFloor" required>
                                <option value="">请选择</option>
                                <option th:each="floorInfo:${floorInfos}" th:text="${floorInfo.floorName}" th:value="${floorInfo.floorName}"></option>
                            </select>
                        </li>
                        <li>
                            <label>租赁开始时间：</label>
                            <input type="text" class="time-input" placeholder="请填写日期" name="tenantTime"/>
                        </li>
                        <li>
                            <label>租赁到期时间：</label>
                            <input type="text" class="time-input" placeholder="请填写日期" name="tenantEndTime"/>
                        </li>
                        <li>
                            <label>收费系数：</label>
                            <input type="text" name="chargeCoefficient"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="tenantStatus">
                                <option value="">所有</option>
                                <option value="0">正常</option>
                                <option value="1">临期</option>
                                <option value="2">到期</option>
                                <option value="3">异常</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="property:tenant:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="property:tenant:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="property:tenant:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="importExcel()" shiro:hasPermission="property:tenant:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="property:tenant:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('property:tenant:edit')}]];
    var removeFlag = [[${@permission.hasPermi('property:tenant:remove')}]];
    var prefix = ctx + "sujian/tenantManagement";
    var options;
   function query(){
       if(options!=null&&options!=undefined){
           var params = $("#bootstrap-table").bootstrapTable('getOptions');
           $("#bootstrap-table").bootstrapTable('refresh', params);
       }else{
           options = {
               url: prefix + "/list",
               createUrl: prefix + "/add",
               updateUrl: prefix + "/edit/{id}",
               removeUrl: prefix + "/remove",
               exportUrl: prefix + "/export",
               importUrl: prefix + "/import",
               importTemplateUrl: prefix + "/importTemplate",
               uniqueId:"tenantId",
               modalName: "租户管理",
               sortName: "serialNumber",
               sortOrder: "asc",
               columns: [{
                   checkbox: true
               },
                   {
                       field: 'serialNumber',
                       title: '序号',
                       visible: false
                   },
                   {
                       field: 'tenantId',
                       title: '租户编号',
                       visible: false
                   },
                   // {
                   //     field: 'projectName',
                   //     title: '项目名称'
                   // },
                   {
                       field: 'tenantName',
                       title: '租户名称或单位'
                   },
                   {
                       field: 'tenantFloor',
                       title: '租户楼层'
                   },
                   {
                       field: 'tenantArea',
                       title: '租户面积(平方米)'
                   },
                   {
                       field: 'emptyArea',
                       title: '空关面积(平方米)'
                   },
                   {
                       field: 'tenantTime',
                       title: '租赁开始时间'
                   },
                   {
                       field: 'tenantEndTime',
                       title: '租赁到期时间'
                   },
                   {
                       field: 'chargeCoefficient',
                       title: '收费系数'
                   },
                   // {
                   //     field: 'tenantTerm',
                   //     title: '租赁期限（年）'
                   // },
                   {
                       field: 'tenantStatus',
                       title: '状态',
                       formatter: function(value, row, index) {
                           if(row.tenantStatus=="0"){
                               return '<span class="label label-primary">正常</span>';
                           }else if(row.tenantStatus=="1"){
                               return '<span class="label label-success">临期</span>';
                           } else if(row.tenantStatus=="2"){
                               return '<span class="label label-warning">到期</span>';
                           } else {
                               return '<span class="label label-danger">异常</span>';
                           }
                       }
                   },
                   {
                       field: 'remark',
                       title: '备注'
                   },
                   {
                       title: '操作',
                       align: 'center',
                       formatter: function(value, row, index) {
                           var actions = [];
                           actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tenantId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                           actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tenantId + '\')"><i class="fa fa-remove"></i>删除</a>');
                           return actions.join('');
                       }
                   }]
           };
           $.table.init(options);
       }

    }
    /*导出接口*/
    function exportExcel(){
        var rows=$.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        };
        $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function() {
            var url = table.options.exportUrl;
            var data = { "ids": rows.join() };
            $.modal.loading("正在导出数据，请稍后...");
            $.post(url,data,function (res) {
                if (res.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                } else if (res.code == web_status.WARNING) {
                    $.modal.alertWarning(res.msg)
                } else {
                    $.modal.alertError(res.msg);
                }
                $.modal.closeLoading();
            })
        });
    }
    /**
     * 导入
     * */
    function importExcel(formId, width, height) {
        table.set();
        var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
        var _width = $.common.isEmpty(width) ? "400" : width;
        var _height = $.common.isEmpty(height) ? "230" : height;
        layer.open({
            type: 1,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '导入' + table.options.modalName + '数据',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function(index, layero){
                var file = layero.find('#drfile').val();
                if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
                    $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                    return false;
                }
                var index = layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData(layero.find('form')[0]);
                $.ajax({
                    url:prefix + "/importExcel",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            $.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="drfile" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果参数已经存在，更新这条数据。"> 是否更新已经存在的参数数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="property:tenant:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>

</html>